// 公共请求
const BASE_URL = "https://yami-mini-api.yiluxdeng.com"
export const request = (options) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + options.url,
			method: options.method || 'GET',
			header: {
				Authorization: uni.getStorageSync('token') ? uni.getStorageSync(
					'token') : undefined

			},
			data: options.data || {},
			success: (res) => {
				if (res.statusCode === 401) { //无权限
					uni.showToast({
						icon: 'error',
						title: '请重新登陆'
					})
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/login/login'
						})
					}, 1000)

					return
				} else if (res.statusCode !== 200) {
					uni.showToast({
						icon: 'error',
						title: '操作错误'
					})
				}
				resolve(res.data)
			},
			fail: (error) => {
				uni.showToast({
					icon: 'error',
					title: '系统错误'
				})
				reject(error)
			}
		})
	})
};
